<h1>FIFA 18</h1>

<div class="title_w_bg">Classement et statistiques </div>

<table class="leaderboard">
  <tr>
    <th> </th>
    <th> </th>
    <th>Pts</th>
    <th>J.</th>
    <th>G.</th>
    <th>G.pr</th>
    <th>G.pn.</th>
    <th>D.</th>
    <th>D.pr</th>
    <th>D.pn.</th>
    <th>Diff.</th>
    <th>bp.</th>
    <th class="lb_br">bc.</th>
  </tr>
  <br>

  <% i = 0
    @players.order(points: :desc).each do |player|
    i = i+1.to_i
  %>
    <tr>
      <td><%= i %></td>
      <td class="lead_team"><%= player.pseudo %></td>
      <td><b><%= player.points %></b></td>
      <td class="lb_br"><%= player.teams.count %> </td>
      <td><%= player.win %> </td>
      <td><%= player.win_prol %> </td>
      <td class="lb_br"><%= player.win_peno %> </td>
      <td><%= player.lose %> </td>
      <td><%= player.lose_prol %> </td>
      <td class="lb_br"><%= player.lose_peno %> </td>
      <td><%= (Team.all.where("player_id= '#{player.id}'").sum(:score))-((Team.where("player_id= '#{player.id}'").collect{|a| a.match.teams.collect{|b| b.score}.sum }.sum)-(Team.all.where("player_id= '#{player.id}'").sum(:score))) %>
      <td><%= Team.all.where("player_id= '#{player.id}'").sum(:score) %></td>
      <td class="lb_br"><%= (Team.where("player_id= '#{player.id}'").collect{|a| a.match.teams.collect{|b| b.score}.sum }.sum)-(Team.all.where("player_id= '#{player.id}'").sum(:score)) %></td>
    </tr>
  <% end %>

</table>


<div class="title_w_bg">Statistiques : Ratios par match </div>

<table class="leaderboard">
  <tr>
    <th> </th>
    <th> </th>
    <th>Pts / match</th>
    <th>Matchs<br>joués</th>
    <th>G.</th>
    <th>G.pr</th>
    <th>G.pn.</th>
    <th>D.</th>
    <th>D.pr</th>
    <th>D.pn.</th>
    <th class="lb_br">Buts /<br>match</th>
    <th class="lb_br">Bc./<br>match</th>
  </tr>
  <br>

  <% i = 0
    @players.order(points: :desc).each do |player|
    i = i+1.to_i
  %>
    <tr>
      <td><%= i %></td>
      <td class="lead_team"><%= player.pseudo %></td>
      <td class="lb_br"><b><%= (player.points.to_f/ player.teams.count).round(2)%></b></td>
      <td class="lb_br"><%= player.teams.count %> </td>

      <td>              <%= number_to_percentage(((100 * player.win) / player.teams.count), precision: 0) %> </td>
      <td>              <%= number_to_percentage(((100 * player.win_prol)/ player.teams.count), precision: 0) %> </td>
      <td class="lb_br"><%= number_to_percentage(((100 * player.win_peno) / player.teams.count), precision: 0) %> </td>
      <td>              <%= number_to_percentage(((100 * player.lose) / player.teams.count), precision: 0) %> </td>
      <td>              <%= number_to_percentage(((100 * player.lose_prol) / player.teams.count), precision: 0) %> </td>
      <td class="lb_br"><%= number_to_percentage(((100 * player.lose_peno) / player.teams.count), precision: 0) %> </td>
      <td><%= (Team.all.where("player_id= '#{player.id}'").sum(:score).to_f / player.teams.count).round(2) %></td>
      <td class="lb_br"><%= (((Team.where("player_id= '#{player.id}'").collect{|a| a.match.teams.collect{|b| b.score}.sum }.sum)-(Team.all.where("player_id= '#{player.id}'").sum(:score))).to_f / player.teams.count).round(2) %></td>
    </tr>
  <% end %>

</table>

<div class="title_w_bg">Légende </div>
<br> Pts = Points
<br> J. = Matchs joués
<br> G. = Matchs gagnés
<br> G.pr = Matchs gagnés après prolongations
<br> G.pn = Matchs gagnés aux penalties
<br>
<br> Diff. = Différence de buts
<br> bp. = Buts pour
<br> bc. = Buts contre
